<template>
	<view>
		<view class="top-content">
			<view class="balance-financing-rate">
				<text
					class="balance-financing-rate-inner">存款周期{{balanceFinancingSetting.term}}天，收益率{{balanceFinancingSetting.rate}}%</text>
			</view>
			<view class="top-content-mid">
				<view class="top-content-mid-l">总资产(USDT)</view>
				<view class="top-content-mid-v">{{moneyFormat(asset.totalAsset)}}</view>
			</view>
			<view class="top-content-bot">
				<view class="top-content-bot-l">
					<view>累计收益</view>
					<view>今日收益</view>
				</view>
				<view class="top-content-bot-v">
					<view>+{{moneyFormat(asset.totalIncome)}}</view>
					<view>+{{moneyFormat(asset.todayIncome)}}</view>
				</view>
			</view>
		</view>
		<view class="every-issues padding-b160">
			<view v-for="(holdingRecord, index) in holdingRecords">
				<view class="every-issue">
					<view class="every-issue-r1">
						<view class="issue-num">{{holdingRecord.issueNum}}期</view>
						<view class="days-remaining">
							<text>剩余</text>
							<text v-show="holdingRecord.daysRemaining != 0">{{holdingRecord.daysRemaining}}天</text>
							<uv-count-down :time="holdingRecord.msRemaining" format="HH时:mm分:ss秒" v-show="holdingRecord.daysRemaining == 0"></uv-count-down>
						</view>
					</view>
					<view class="every-issue-r2">
						<view class="every-issue-r2-t">
							<view>持有资产(USDT)</view>
							<view>累计收益(USDT)</view>
							<view>今日收益(USDT)</view>
						</view>
						<view class="every-issue-r2-b">
							<view>{{holdingRecord.asset}}</view>
							<view>+{{holdingRecord.totalIncome}}</view>
							<view>+{{holdingRecord.todayIncome}}</view>
						</view>
					</view>
				</view>

			</view>
		</view>
		<view class="no-data" v-show="noDataFlag">
			<uv-empty text="暂无持有记录" mode="list"></uv-empty>
		</view>
		<view class="fixed-bottom">
			<view class="fixed-bottom-inner">
				<uv-button type="primary" text="转入" size="large" @click="balanceFinancingBuyInPage"></uv-button>
			</view>
		</view>

	</view>
</template>

<script>
	import common from '@/common/common'
	export default {
		data() {
			return {
				balanceFinancingSetting: '',
				asset: '',
				holdingRecords: [],
				noDataFlag: false,
			}
		},
		onLoad(option) {
			this.getBalanceFinancingSetting();
			this.getMyBalanceFinancingAsset();
			this.findMyHoldingBalanceFinancingBuyInRecord();
		},
		methods: {


			getBalanceFinancingSetting() {
				var that = this;
				uni.$uv.http.get('/setting/getBalanceFinancingSetting').then(res => {
					that.balanceFinancingSetting = res.data;
				});
			},

			balanceFinancingBuyInPage() {
				var that = this;
				uni.$once('balanceFinancingBuyInRefresh', function(data) {
					that.getMyBalanceFinancingAsset();
					that.findMyHoldingBalanceFinancingBuyInRecord();
				});
				uni.navigateTo({
					url: '../balanceFinancingBuyIn/balanceFinancingBuyIn'
				});
			},

			findMyHoldingBalanceFinancingBuyInRecord() {
				var that = this;
				uni.$uv.http.get('/balanceFinancing/findMyHoldingBalanceFinancingBuyInRecord').then(res => {
					that.holdingRecords = res.data;
					that.noDataFlag = that.holdingRecords.length == 0;
				});
			},

			getMyBalanceFinancingAsset() {
				var that = this;
				uni.$uv.http.get('/balanceFinancing/getMyBalanceFinancingAsset').then(res => {
					that.asset = res.data;
				});
			},

			moneyFormat(amount) {
				return common.moneyFormat(amount);
			},
		}
	}
</script>

<style>
	.balance-financing-rate {
		display: flex;
		justify-content: center;
		padding-bottom: 16rpx;
	}

	.balance-financing-rate-inner {
		background: #009f00;
		padding: 4rpx 24rpx;
		font-size: small;
		border-radius: 16rpx;
	}

	.every-issues {}

	.every-issue {
		border-radius: 16rpx;
		background: #e8e8e8;
		border: 4rpx solid rgb(240, 242, 245);
		margin-left: 32rpx;
		margin-right: 32rpx;
		margin-top: 32rpx;
	}

	.every-issue-r1 {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-left: 32rpx;
		padding-right: 32rpx;
		border-bottom: 1rpx solid #dcdee0;
		line-height: 2.8;
		font-size: small;
	}

	.issue-num {}

	.days-remaining {
		color: #969799;
		display: flex;
		align-items: center;

		.uv-count-down__text {
			font-size: small;
		}
	}



	.every-issue-r2 {
		padding-top: 16rpx;
		padding-bottom: 16rpx;
	}

	.every-issue-r2-t {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-left: 32rpx;
		padding-right: 32rpx;
		color: #969799;
		font-size: small;
		line-height: 1.6;
	}

	.every-issue-r2-t view {}

	.every-issue-r2-b {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-left: 32rpx;
		padding-right: 32rpx;
		font-size: small;
		line-height: 1.6;
	}

	.every-issue-r2-b view {}

	.top-content {
		color: #fff;
		padding: 32rpx;
		background: linear-gradient(127deg, #0068b7 10%, #b9d4e9);
	}

	.top-content-mid {
		text-align: center;
		padding-bottom: 32rpx;
	}

	.top-content-mid-l {
		font-size: 26rpx;
		padding-bottom: 10rpx;
	}

	.top-content-mid-v {
		font-size: 52rpx;
	}

	.top-content-bot {}

	.top-content-bot-l {
		display: flex;
		justify-content: space-between;
		font-size: small;
		line-height: 2;
	}

	.top-content-bot-v {
		display: flex;
		justify-content: space-between;
	}
</style>